<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <!--文件上传成功➡调用handleSuccess方法-->
    <el-upload
            action="/upload"
            name="picFile"
            limit="3"

            list-type="picture-card"

            :on-success="handleSuccess"

            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
        <i class="el-icon-plus"></i>

    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>

</div>

</body>
<!--引入axios和vue框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false
            }
        },
        methods:{
            // elementUi粘贴过来的两个方法

            // 删除文件的实现:请求中需要标注删除的文件名➡
            // 添加成功的时候返回给客户端对应的“唯一”文件名➡
            // 文件名就是handleSuccess(response）中的response!!!
            handleRemove(file, fileList) {
                console.log(file, fileList);
                axios.get("/remove?name="+file.response).then(function () {
                    console.log("删除完成！")
                })
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            // elementUi的隐藏工作
            handleSuccess(response,file,fileList){
                console.log(response);
            }
        }
    })
</script>
</html>